﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Reactive.Linq;

namespace FlashlightRecorder.ViewModels
{
    public class Color_Model : INotifyPropertyChanged
    {

        public Color_Model()
        {
            var cl = Observable.FromEvent<PropertyChangedEventHandler, PropertyChangedEventArgs>(
                                   ac => (s, e) => ac(e),
                                   eh => this.PropertyChanged += eh,
                                   eh => this.PropertyChanged -= eh
                               )
                               .Where(x => x.PropertyName != "Color");
            cl.Subscribe(
                _ =>
                {
                    Color = Color.FromArgb(255, (byte)this.Red, (byte)this.Green, (byte)this.Blue);

                }
                );

            Red = 255;
            Green = 0;
            Blue = 0;

        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }


        Color _Color;

        public Color Color
        {
            get { return _Color; }
            set
            {
                _Color = value;
                NotifyPropertyChanged("Color");
            }
        }




        double _Red;

        public double Red
        {
            get { return _Red; }
            set
            {
                _Red = value;
                NotifyPropertyChanged("Red");
            }
        }
        double _Green;

        public double Green
        {
            get { return _Green; }
            set
            {
                _Green = value;
                NotifyPropertyChanged("Green");
            }
        }
        double _Blue;

        public double Blue
        {
            get { return _Blue; }
            set
            {
                _Blue = value;
                NotifyPropertyChanged("Blue");
            }
        }

    }
}
